package com.fulihui.wgj.admin.api.fans;

import com.fulihui.common.result.web.Result;
import com.fulihui.wgj.admin.api.base.BaseController;
import com.fulihui.wgj.admin.api.fans.request.HistorySendUserRequest;
import com.fulihui.wgj.admin.api.fans.request.SearchFansRequest;
import com.fulihui.wgj.admin.api.fans.vo.FansInfoVO;
import com.fulihui.wgj.admin.api.fans.vo.HistorySendUserVO;
import com.fulihui.wgj.admin.integration.WxUserInfoServiceClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Objects;

/**
 * @author: Levon
 * @date: 2018-07-25 15:11
 */
@RestController
@RequestMapping("/fans")
@Api(tags = "微信粉丝相关接口")
public class FansManageController extends BaseController {

    @Autowired
    private WxUserInfoServiceClient wxUserInfoServiceClient;

    @PostMapping("/list")
    @ApiOperation("获取历史发送用户列表")
    public Result<List<HistorySendUserVO>> queryhistorySendFans(HttpServletRequest request) {
        HistorySendUserRequest sendUserRequest = new HistorySendUserRequest();
        sendUserRequest.setAppId(getAppid(request));
        return wxUserInfoServiceClient.queryHistorySendFans(sendUserRequest);
    }

    @PostMapping("/searchFans")
    @ApiOperation("根据昵称查询粉丝信息")
    public Result<List<FansInfoVO>> searchFans(@RequestBody @Valid SearchFansRequest request, BindingResult validResult,
                                               HttpServletRequest servletRequest) {
        Result result = valid(validResult);
        if (Objects.nonNull(result)) {
            return result;
        }
        request.setAppId(getAppid(servletRequest));
        return wxUserInfoServiceClient.searchFans(request);
    }

}
